MAX = 1000000
isp = [1 for i in xrange(MAX)]
fact = [{} for i in xrange(MAX)]
p = []
for i in xrange(2, MAX):
    if isp[i]:
        p.append(i)
        for j in xrange(i + i, MAX, i):
            isp[j] = 0
        for j in xrange(i, MAX, i):
            fact[j][i] = 1

for i in xrange(2, MAX - 4):
    good = 1
    t = {}
    for j in xrange(i, i + 4):
        if not good:
            break
        for f in fact[j]:
            if f in t:
                good = 0
                break
            t[f] = 1

    if good:
        print i
        break

